
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        li{
            margin:10px 0;

        }
    </style>
    　　<link rel="apple-touch-icon" href="/apple-touch-icon.png（180*180）">
    　　<link rel="icon" href="/favicon.ico（32*32）">
    <!--<script src=”//api.html5media.info/1.1.8/html5media.min.js></script>-->
    <script src="//cdn.jsdelivr.net/npm/eruda"></script>
    <script>eruda.init();</script>
</head>
<body>
<ol>
    <li>
        <button id="btn1" onclick="goOne()">开启蓝牙(num=5表示蓝牙已开启成功，其他未开启)</button>
    </li>
    <li>
        <button onclick="goTwo()">关闭蓝牙模块(num=1成功,0失败),调用该方法将断开所有已建立的链接并释放系统资源</button>
    </li>
    <li>
        <button onclick="goThree()">获取本机蓝牙适配器状态(num=5表示蓝牙已开启，其他未开启)</button>
    </li>
    <li>
        <button onclick="goFour()">监听蓝牙适配器状态变化事件</button>
    </li>
    <li>
        <button onclick="goFive()">开始扫描周边设备</button>
    </li>
    <li>
        <button onclick="goSix()">关闭扫描周边设备</button>
    </li>
    <li>
        <button onclick="goSeven()">获取所有已发现的蓝牙设备</button>
    </li>
    <li>
        <button onclick="goEight()">根据 uuid 获取处于已连接状态的设备</button>
    </li>
    <li>
        <button onclick="goNine()">监听寻找到新设备的事件(返回的设备identifier数组)</button>
    </li>
    <li>
        <button onclick="goTen()">连接低功耗蓝牙设备</button>
    </li>
    <li>
        <button onclick="goEleven()">断开与低功耗蓝牙设备的连接</button>
    </li>
    <li>
        <button onclick="gotewlve()">获取蓝牙设备所有 service（服务)</button>
    </li>
    <li>
        <button onclick="goThirteen()">获取蓝牙设备所有 characteristic（特征值）</button>
    </li>
    <li>
        <button onclick="goFourteen()">读取低功耗蓝牙设备的特征值的二进制数据值 （需支持read）</button>
    </li>
    <li>
        <button onclick="goFifteen()">向低功耗蓝牙设备特征值中写入二进制数据 （需支持write）</button>
    </li>
    <li>
        <button onclick="goSixteen()">启用低功耗蓝牙设备特征值变化时的 notify 功能 （需支持notify）</button>
    </li>
    <li>
        <button onclick="sevenTeen()">监听低功耗蓝牙连接的错误事件，包括设备丢失，连接异常断开等等(1已断开，2正在连接，3已经连接，4正在断开)</button>
    </li>
    <li>
        <button onclick="eightTeen()">监听低功耗蓝牙设备的特征值变化。必须先启用notify接口才能接收到设备推送的notification。</button>
    </li>

    <li>
        <button onclick="nineTeen()">系统信息获取</button>
    </li>

    <li>
        <button onclick="twenty()">数据写入</button>
    </li>

    <li>
        <button onclick="twentyOne()">数据读取</button>
    </li>

    <li>
        <button onclick="twentyTwo()">数据删除</button>
    </li>

    <li>
        <button onclick="twentyThree()">数据清空</button>
    </li>

</ol>
<script src="./eruda.min.js"></script>
<script>

    // eruda 调试按钮
    var el = document.createElement('div');
    document.body.appendChild(el);

    eruda.init({
        container: el,
        tool: ['console', 'elements', 'info']
    });

    function goOne(){

        console.log(window.hilink.openBluetoothAdapter());
    }

    function openBluetoothAdapterCallback(resultStr) {
        console.log(resultStr);
    }

    function goTwo(){
        console.log(window.hilink.closeBluetoothAdapter());
    }

    function closeBluetoothAdapterCallback(resultStr) {
        console.log(resultStr);
    }

    function goThree(){
        hilink.getBluetoothAdapterState("getBluetoothAdapterStateCallback");
    }

    function getBluetoothAdapterStateCallback(resultStr) {
        console.log(resultStr);
    }

    function goFour(){

        hilink.onBluetoothAdapterStateChange("onBluetoothAdapterStateChangeCallback");
    }

    function onBluetoothAdapterStateChangeCallback(resultStr) {
        console.log(resultStr);
    }

    function goFive(){

        console.log(window.hilink.startBluetoothDevicesDiscovery([],0,0));
    }

    function goSix(){

        console.log(window.hilink.stopBluetoothDevicesDiscovery());
    }

    function goSeven(){

        hilink.getBluetoothDevices("getBluetoothDevicesCallback");
    }

    function getBluetoothDevicesCallback(resultStr) {
        console.log(resultStr);
    }

    function goEight(){

        hilink.getConnectedBluetoothDevices([],"getConnectedBluetoothDevicesCallback");
    }

    function getConnectedBluetoothDevicesCallback(resultStr) {
        console.log(resultStr);
    }

    function goNine(){

        hilink.onBluetoothDeviceFound("onBluetoothDeviceFoundCallback");
    }

    function onBluetoothDeviceFoundCallback(resultStr) {
        console.log(resultStr);
    }

    function goTen(){

        console.log(window.hilink.createBLEConnection('9F3CE2AB-1CF5-F4BA-42EB-B10B578A5EF6'));
    }

    function goEleven(){

        console.log(window.hilink.closeBLEConnection('9F3CE2AB-1CF5-F4BA-42EB-B10B578A5EF6'));
    }

    function gotewlve(){

        hilink.getBLEDeviceServices('9F3CE2AB-1CF5-F4BA-42EB-B10B578A5EF6',"getBLEDeviceServicesCallback");
    }

    function getBLEDeviceServicesCallback(resultStr) {
        console.log(resultStr);
    }

    function goThirteen(){

        var serviceUuid = 'FFE5';

        hilink.getBLEDeviceCharacteristics('9F3CE2AB-1CF5-F4BA-42EB-B10B578A5EF6',serviceUuid,"getBLEDeviceCharacteristicsCallback");

    }

    function getBLEDeviceCharacteristicsCallback(resultStr) {
        console.log(resultStr);
    }

    function goFourteen(){

        var serviceUuid = 'FFE5';
        var characteristic = 'FFE9';
        hilink.readBLECharacteristicValue('9F3CE2AB-1CF5-F4BA-42EB-B10B578A5EF6',serviceUuid,characteristic,"readBLECharacteristicValueCallback");
    }

    function readBLECharacteristicValueCallback(resultStr) {
        console.log(resultStr);
    }

    function goFifteen(){

        var serviceUuid = 'FFE5';
        var characteristic = 'FFE9';
        var writeStr = 'AAAA1301A5550F784F01 0000000000080500004D 5555';
        window.hilink.writeBLECharacteristicValue('9F3CE2AB-1CF5-F4BA-42EB-B10B578A5EF6',serviceUuid,characteristic,'AAAA1301A5550F784F01',"writeBLECharacteristicValueCallback");
        window.hilink.writeBLECharacteristicValue('9F3CE2AB-1CF5-F4BA-42EB-B10B578A5EF6',serviceUuid,characteristic,'0000000000080500004D',"writeBLECharacteristicValueCallback");
        window.hilink.writeBLECharacteristicValue('9F3CE2AB-1CF5-F4BA-42EB-B10B578A5EF6',serviceUuid,characteristic,'5555',"writeBLECharacteristicValueCallback");
    }

    function writeBLECharacteristicValueCallback(resultStr) {
        console.log(resultStr);
    }

    function goSixteen(){

        var serviceUuid = 'FFE0';
        var characteristic = 'FFE4';
        console.log(window.hilink.notifyBLECharacteristicValueChange('9F3CE2AB-1CF5-F4BA-42EB-B10B578A5EF6',serviceUuid,characteristic,1));
    }

    function sevenTeen(){
        window.hilink.onBLEConnectionStateChange("onBLEConnectionStateChangedCallback");
    }


    function onBLEConnectionStateChangedCallback(resultStr) {
        console.log(resultStr);
    }

    function eightTeen(){

        window.hilink.onBLECharacteristicValueChange("onBLECharacteristicValueChangeCallback");
    }

    function onBLECharacteristicValueChangeCallback(resultStr) {
        console.log(resultStr);
    }

    function nineTeen(){

        window.hilink.getSystemInfoSync("getSystemInfoSyncCallback");
    }

    function getSystemInfoSyncCallback(resultStr) {
        console.log(resultStr);
    }

    function twenty(){
        // NjI2MjcyNzYyNjIyNzI3
        console.log(window.hilink.setStorageSync('yuKEY','12898755556277722266666y'));
    }

    function twentyOne(){

        console.log(window.hilink.getStorageSync('yuKEY'));
    }

    function twentyTwo() {

        console.log(window.hilink.removeStorageSync('yuKEY'));
    }

    function twentyThree() {

        console.log(window.hilink.clearStorageSync());
    }


</script>


</body>
</html>
